import router from './router'
import store from '@/store'
import { Message } from 'element-ui'

// const whiteList = ['/login'] // no redirect whitelist
const whiteList = ['/login']
// 导航守卫
router.beforeEach(async(to, from, next) => {
  // console.log(to, from)
  const token = store.getters.token
  // console.log(token)
  if (token && to.path === '/login') {
    next('/')
    Message.warning('你已经登录过了!')
  }
  if (token && to.path !== '/login') {
    next()
  }
  if (!token && to.path !== '/login') {
    next('/login')
    Message.warning('请先登录!')
  }
  if (!token && whiteList.includes(to.path)) {
    next()
  }
})

// 全局后置钩子
router.afterEach(() => {
  // finish progress bar

})
